package edu.calvin.djs32.cs214.interpreters.size;

import static org.junit.Assert.assertEquals;

import org.junit.Before;
import org.junit.Test;

import edu.calvin.cs214.hobbes2008.IntegerTIR;
import edu.calvin.cs214.hobbes2008.StringTIR;
import edu.calvin.cs214.hobbes2008.TupleTIR;



public class SizeTest {
	private Size mySize;
	
	@Before
	public void setUp() {
		mySize = new Size();
	}
	
	@Test
	public void integerShouldBe1(){
		assertEquals(1, mySize.visitInteger(new IntegerTIR(1)));
		assertEquals(1, mySize.visitInteger(new IntegerTIR(1000)));
		assertEquals(1, mySize.visitInteger(new IntegerTIR(-1)));
	}
	
	@Test
	public void stringShouldBe1(){
		assertEquals(1, mySize.visitString(new StringTIR("foo")));
		assertEquals(1, mySize.visitString(new StringTIR("bar")));
		assertEquals(1, mySize.visitString(new StringTIR("foo bar")));
	}
	
	@Test
	public void tupleShouldBeOneMoreThanElements(){
		assertEquals(1, mySize.visitTuple(new TupleTIR()));
		assertEquals(2, mySize.visitTuple(new TupleTIR(new TupleTIR())));
		assertEquals(4, mySize.visitTuple(new TupleTIR(new TupleTIR(new TupleTIR(new TupleTIR())))));
	}
	
	@Test
	public void shouldDoMixes(){
		assertEquals(4, mySize.visitTuple(new TupleTIR(new IntegerTIR(1), new IntegerTIR(2), new StringTIR("foo"))));
		assertEquals(6, mySize.visitTuple(
				new TupleTIR(new IntegerTIR(1), 
				new TupleTIR(new TupleTIR(new IntegerTIR(2)), new IntegerTIR(3)))));
	}
}
